package com.yh.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.druid.support.json.JSONParser;
import com.google.gson.annotations.JsonAdapter;
import com.yh.bean.Dept;
import com.yh.service.ManageService;
/*
 * 
 * 部门管理
 */
@Controller
@Scope("prototype")
@RequestMapping("/dept")
public class DeptManageController {
	@Autowired
	private ManageService service;
	
	//新增部门
	@RequestMapping("/add")
	@ResponseBody
	public String addDept(Dept dept){	
		System.out.println(dept+"------------------------------------");
		int a=service.addDept(dept);		
		return "addsuccess";
	}
	
	//查询所有部门
	@RequestMapping("/queryDept")
	@ResponseBody
	public List<Dept> queryAllDept(int deptid){
		
		List<Dept> listDept=service.queryListDept(deptid);
		
		for(Dept dept:listDept){
			System.out.println(dept.getDept_name()+",,,,,,"+dept.getUser().getReal_name());
		}
		
		return listDept;
		
	}
	
	//修改部门
	@RequestMapping("/updateDept")
	@ResponseBody
	public String updateDept(Dept dept){
		System.out.println("update进来了************************************");
		System.out.println(dept);
		int a=service.updateDept(dept);
		
		return "updatesuccess";
	}
  
	//根据部门id删除部门
	@RequestMapping("/delDept")
	@ResponseBody
	public String delDept(int deptid){
		int a=service.delDept(deptid);
		return "delsuccess";
	}
	
}
